package com.desay.pangoo.itmt.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.persistence.*;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.Data;

/**
 * @author uidq1163 on [2022年09月22日上午10:16:03] <br>
 *         work group Tech classification 在线提案审核流程信息管理
 * @Modified By： [修改人] on [修改日期] for [修改说明]
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "tech_online_review")
@Data
public class TechOnlineReviewEntity extends BaseEntity implements Serializable {

	private static final long serialVersionUID = -3501806961782384501L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", columnDefinition = "bigint COMMENT '主键'")
	private Long id;

	/**
	 * 流程结束期限：评审会时间+1个工作日）
	 */
	@Column(name = "due_date", nullable = false, columnDefinition = "datetime default CURRENT_TIMESTAMP COMMENT '截至日期'")
	private Date dueDate;

	@Column(name = "proposal_name", nullable = false, columnDefinition = "varchar(1000) COMMENT '提案名称'")
	private String proposalName;

	/** 责任人 */
	@Column(name = "responsible", columnDefinition = "varchar(500) COMMENT '责任人'")
	private String responsible;

	@Column(name = "description", nullable = true, columnDefinition = "mediumtext COMMENT '说明'")
	private String description;

	@Column(name = "tech_level", nullable = true, columnDefinition = "int COMMENT '技术等级:核心:1，关键:2，通用:3，一般:4'")
	private Integer techLevel;

	@Column(name = "is_cross", nullable = true, columnDefinition = "bit COMMENT '是否跨域技术'")
	private Boolean isCross;

	@Column(name = "is_disruptive", nullable = true, columnDefinition = "bit COMMENT '是否颠覆性技术'")
	private Boolean isDisruptive;

	@Column(name = "is_cross_review", nullable = true, columnDefinition = "bit COMMENT '是否跨域技术'")
	private Boolean isCrossReview;

	@Column(name = "disruptive_review_avg", nullable = true, columnDefinition = "double COMMENT '颠覆性技术认证得分'")
	private Double disruptiveReview;

	/**
	 * 项目对应的时间线状态
	 */
	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "tech_online_review_id")
	@JsonIgnoreProperties("techOnlineReview")
	private Set<TechOnlineReviewFileEntity> files;

	@ManyToOne(fetch = FetchType.EAGER, optional = true)
	@JoinColumn(name = "work_group_id")
	private WorkGroupEntity workGroup;

	@ManyToOne(fetch = FetchType.EAGER, optional = true)
	@JoinColumn(name = "crossbreed_work_group_id")
	private WorkGroupEntity crossBreedWorkGroup;

	@Column(name = "road_map", nullable = true, columnDefinition = "varchar(255) COMMENT '技术路线'")
	private String roadMap;

	@Column(name = "subsidiary", nullable = true, columnDefinition = "varchar(255) COMMENT '子技术'")
	private String subsidiary;

	@Column(name = "review_result", nullable = true, columnDefinition = "bit COMMENT '评审结果：1通过，0不通过'")
	private Boolean reviewResult;

	/**
	 * 提案申请关联的课题
	 */
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "ref_review_tech_project", joinColumns = {
			@JoinColumn(name = "tech_review_id") }, inverseJoinColumns = {
					@JoinColumn(name = "tech_project_id") }, uniqueConstraints = {
							@UniqueConstraint(columnNames = { "tech_review_id", "tech_project_id" }) })
	@JsonIgnoreProperties({ "parent", "children", "techOnlineReview", "techYearQuarters", "platforms" })
	private Set<TechProjectInfoEntity> techProjects;

	/**
	 * 开发责任主体
	 */
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "ref_review_duty_bu_div", joinColumns = {
			@JoinColumn(name = "review_id") }, inverseJoinColumns = {
					@JoinColumn(name = "bu_id") }, uniqueConstraints = {
							@UniqueConstraint(columnNames = { "review_id", "bu_id" }) })
	private Set<BUDivEntity> dutyBuss;

	/**
	 * 开发费用归属
	 */
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "ref_review_cost_bu_div", joinColumns = {
			@JoinColumn(name = "review_id") }, inverseJoinColumns = {
					@JoinColumn(name = "bu_id") }, uniqueConstraints = {
							@UniqueConstraint(columnNames = { "review_id", "bu_id" }) })
	private Set<BUDivEntity> costBuss;


	/**
	 * 评审会时间
	 */
	@Column(name = "review_date", nullable = true, columnDefinition = "datetime default CURRENT_TIMESTAMP COMMENT '评审会时间'")
	private Date reviewDate;
	/**
	 * 评审会时间
	 */
	@Column(name = "review_date_hours", nullable = true, columnDefinition = "varchar(50) COMMENT '评审会时间(hh:mm ~ hh:mm)'")
	private String reviewDateHours;

	/**
	 * TMT相关性反馈期限(当前日期+2个工作日）
	 */
	@Column(name = "tmtReview_due_date", nullable = true, columnDefinition = "datetime default CURRENT_TIMESTAMP COMMENT 'TMT相关性反馈期限(当前日期+2个工作日）'")
	private Date tmtReviewDueDate;

	/**
	 * 选择评审类型
	 */
	@Column(name = "review_type", nullable = false, columnDefinition = "int default 1 COMMENT '评审类型:技术规划评审:1，技术定义与研究任务书评审:2，技术成果交付评审:3,BU TMT批注技术课题：4'")
	private Integer reviewType;

	/**
	 * 存在多次评审的情况下自动根据上一次评审信息获取
	 */
	@OneToOne(fetch = FetchType.LAZY, cascade = { CascadeType.REFRESH }, optional = true)
	@JoinColumn(name = "parent_id")
	@JsonIgnoreProperties({ "children" })
	private TechOnlineReviewEntity parent;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent", cascade = { CascadeType.REFRESH, CascadeType.REMOVE,
			CascadeType.MERGE })
	@JsonIgnoreProperties({ "parent" })
	private Set<TechOnlineReviewEntity> children;

	/**
	 * 是否开启TMT评审反馈
	 */
	@Column(name = "open_review", nullable = true, columnDefinition = "bit COMMENT '是否开始评审反馈:null未开启评审，1开始评审，0：关闭评审'")
	private Boolean openReview;

	/**
	 * 是否开启TMT评审反馈
	 */
	@Column(name = "open_relevant", nullable = true, columnDefinition = "bit default 1 COMMENT '是否开始ITMT Leader相关性反馈:1开始，0：关闭'")
	private Boolean openRelevant;
	@Column(name = "task_id", nullable = true, columnDefinition = "varchar(50) COMMENT '飞书提醒任务ID'")
	private String taskId;
	@Column(name = "event_id", nullable = true, columnDefinition = "varchar(50) COMMENT '飞书日程ID'")
	private String eventId;

	/** 上级技术点（可选）， */
	@Column(name = "parent_tech", columnDefinition = "varchar(255) COMMENT '上级技术点'")
	private String parentTech;

	/** 产品功能点（必填） */
	@Column(name = "product_function", columnDefinition = "varchar(500) COMMENT '产品功能点'")
	private String productFunction;

	/**
	 * 技术应用范围（必填），
	 */
	@Column(name = "tech_scope", columnDefinition = "varchar(500) COMMENT '技术应用范围'")
	private String techScope;

	/**
	 * 技术性能指标 （必填）
	 */
	@Column(name = "tech_performance", columnDefinition = "varchar(255) COMMENT '技术性能指标'")
	private String techPerformance;
	/**
	 * 技术来源（必填），
	 */
	@Column(name = "tech_source", columnDefinition = "varchar(255) COMMENT '技术来源'")
	private String techSource;
	/**
	 * 预计第一次应用时间（必填）
	 */
	@Column(name = "first_use_date", columnDefinition = "varchar(10) COMMENT '预计第一次应用时间'")
	private String firstUseDate;
	/**
	 * 技术领先性:领先 追平 落后 （ 三选一）
	 */
	@Column(name = "technology_leadership", nullable = true, columnDefinition = "int COMMENT '技术领先性'")
	private Integer technologyLeadership;

	/**
	 * 技术贡献性:创新技术 主要卖点 次要卖点 基础技术 （ 四选一）
	 */
	@Column(name = "technology_contribution", nullable = true, columnDefinition = "int COMMENT '技术贡献性'")
	private Integer technologyContribution;

	/**
	 * 核心技术
	 */
	@Column(name = "core_technology", nullable = true, columnDefinition = "int COMMENT '核心技术'")
	private Integer coreTechnology;
	/**
	 * 是否是第一次审核
	 */
	@Column(name = "is_pl_review", nullable = true, columnDefinition = "bit COMMENT '是否是PL审核阶段'")
	private Boolean isPlReview;
	/**
	 * 是否是PLTMT技术课题注册的技术交付申请
	 */
	@Column(name = "is_type4_commit", nullable = true, columnDefinition = "bit COMMENT '是否是PLTMT技术课题注册的技术交付申请'")
	private Boolean isType4Commit;

	/** 技术领头人 */
	@Column(name = "tech_leaders", columnDefinition = "text COMMENT '技术领头人'")
	private String techLeaders;

	/** 核心成员 */
	@Column(name = "core_members", columnDefinition = "text COMMENT '核心成员'")
	private String coreMembers;
	/** 一般成员 */
	@Column(name = "general_members", columnDefinition = "text COMMENT '一般成员'")
	private String generalMembers;

	@Transient
	private List<ProjectEntity> projectList;
	/**
	 * 技术领先性:领先 追平 落后 （ 三选一）
	 */
	@Column(name = "final_technology_leadership", nullable = true, columnDefinition = "int COMMENT '最终技术领先性'")
	private Integer finalTechnologyLeadership;

	/**
	 * 技术贡献性:创新技术 主要卖点 次要卖点 基础技术 （ 四选一）
	 */
	@Column(name = "final_technology_contribution", nullable = true, columnDefinition = "int COMMENT '最终技术贡献性'")
	private Integer finalTechnologyContribution;
	/**
	 * 技术交付环节关联提案
	 */
	@Column(name = "relatedReviewEntityId", nullable = true, columnDefinition = "bigint COMMENT '关联提案id'")
	private Long relatedReviewEntityId;
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		TechOnlineReviewEntity other = (TechOnlineReviewEntity) obj;
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		return true;
	}
}
